package com.heima.wemedia.controller.v1;

import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.AdChannel;
import com.heima.wemedia.service.WmChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/channel")
public class WmchannelController {

    @Autowired
    public WmChannelService wmChannelService;

    @GetMapping("/channels")
    public ResponseResult findAll(){

        return wmChannelService.findAll();
    }

    /**
     * 带条件查询频道列表
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody ChannelDto dto){
        return wmChannelService.pageList(dto);
    }

    /**
     * 保存频道
     * @param adChannel
     * @return
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody AdChannel adChannel){
        return wmChannelService.saveAdChannel(adChannel);
    }

    /**
     * 删除频道
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    public ResponseResult del(@PathVariable Integer id){
        return wmChannelService.delAdChannel(id);
    }

    /**
     * 修改
     * @param adChannel
     * @return
     */
    @PostMapping("/update")
    public ResponseResult update(@RequestBody AdChannel adChannel){
        return wmChannelService.updateAdChannel(adChannel);
    }
}